import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @作者 ： opentestcase024 @时间： 2023/3/6
 * @测试点：jdbc连接参数autoBalance为leastconn，enableQuickAutoBalance参数异常，正常报错
 **/
public class JDBC_QuikAutoBalance_Case0004 {
	public static void main(String[] args) throws Exception {
		String err1_msg = null, err2_msg = null, err3_msg = null;
		System.out.println("----------start----------");
		List<Connection> connections = new ArrayList<>();
		System.out.println("----------point1：连接参数enableQuickAutoBalance为true包含大写----------");
		String url1 = "jdbc:postgresql://" + args[0] + "/" + args[1]
				+ "?loggerLevel=info&autoBalance=leastconn&enableQuickAutoBalance=TRUE";
		try {
			Connection connection = DriverManager.getConnection(url1, args[2], args[3]);
			connections.add(connection);
		} catch (SQLException e) {
			err1_msg = e.getMessage();
			System.out.println(err1_msg);
		}
		System.out.println("----------point2：连接参数enableQuickAutoBalance为数字----------");
		String url2 = "jdbc:postgresql://" + args[0] + "/" + args[1]
				+ "?loggerLevel=info&autoBalance=leastconn&enableQuickAutoBalance=12";
		try {
			Connection connection = DriverManager.getConnection(url2, args[2], args[3]);
			connections.add(connection);
		} catch (SQLException e) {
			err2_msg = e.getMessage();
			System.out.println(err2_msg);
		}
		System.out.println("----------point3：连接参数enableQuickAutoBalance为False包含大写----------");
		String url3 = "jdbc:postgresql://" + args[0] + "/" + args[1]
				+ "?loggerLevel=info&autoBalance=leastconn&enableQuickAutoBalance=False";
		try {
			Connection connection = DriverManager.getConnection(url3, args[2], args[3]);
			connections.add(connection);
		} catch (SQLException e) {
			err3_msg = e.getMessage();
			System.out.println(err3_msg);
		}
		System.out.println("----------sleep 10s----------");
		TimeUnit.SECONDS.sleep(10);
		// sleep过程中数据库节点查询建连数量
		String err1_flag = "Parameter enableQuickAutoBalance=TRUE parsed failed, value range: {true, false}).";
		String err2_flag = "Parameter enableQuickAutoBalance=12 parsed failed, value range: {true, false}).";
		String err3_flag = "Parameter enableQuickAutoBalance=False parsed failed, value range: {true, false}).";
		System.out.println("----------end----------");
		if (err1_msg.indexOf(err1_flag) != -1 && err2_msg.indexOf(err2_flag) != -1
				&& err3_msg.indexOf(err3_flag) != -1) {
			System.out.println("----The verification is correct.----");
		}
	}
}
